//
//  FWTopWindownController.m
//  BirdLoveSheep
//
//  Created by wwj on 16/4/5.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWTopWindownController.h"

@interface FWTopWindownController ()

@end

@implementation FWTopWindownController

+ (instancetype)sharedTopWindwonVC{
    static FWTopWindownController *sharedClass;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedClass = [[FWTopWindownController alloc] init];
    });
    return sharedClass;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
}

- (void)setIsHidden:(BOOL)isHidden{
    _isHidden = isHidden;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle{
    _statusBarStyle = statusBarStyle;
    [self setNeedsStatusBarAppearanceUpdate];
}

- (BOOL)prefersStatusBarHidden{
    return self.isHidden;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return self.statusBarStyle;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self searchScrollerView:[UIApplication sharedApplication].keyWindow];
}

- (void)searchScrollerView:(UIView *)view{
    for (UIView *chidV in view.subviews) {
        if ([chidV isKindOfClass:[UIScrollView class]] && [chidV isShowingOnKeyWindow]) {
            UIScrollView *scrollerView = (UIScrollView *)chidV;
            CGPoint offset = scrollerView.contentOffset;
            offset.y = -scrollerView.contentInset.top;
            [scrollerView setContentOffset:offset animated:YES];
        }
        [self searchScrollerView:chidV];
    }
}

@end
